<?php
/*
 * 手机客户端 我的关注接口
 * 传入参数 
 * 2013-12-011
 */
include "inc/public_header.php";
include "func/user.php";				//用户信息处理函数

//头像根路径
$LOGO_BASE_PATH = "http://www.chinalaohu.com/modules/miniature.php?w=150&h=150&p=/uploads/zjl_ilogo/";

//默认头像
$LOGO_DEFAULT_PATH = "http://www.chinalaohu.com/images/zjl/logo.png";

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid = $uInfoArr["uid"];//用户信息主键

$reJson = array();//构建返回值
 
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数
$hd_id			= $_REQUEST["hd_id"];			//活动主键

if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 8; //默认每页20条
}

$reJson["success"] = "1";

//关注人的总数
$sql = "select count(0) as ct from user_base a inner join new_weituo_fensi b on a.uid=b.fuid where b.fuid='".$uid."' ";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and b.hd_id='".$hd_id."' ";
}
$db->query($sql);
$db->next_record();
$reJson["count"] = $db->f("ct");

//关注人信息列表
$sql ="
	select
		 c.fuid 
		,c.uid
        ,b.nickname as nickname
        ,b.ilogo_path as userIcon
        ,b.xuexiao as userCollege
        ,e.ct as attention
        ,d.ct as fans
        ,f.ct as works
		,a.mobile
		,g.id as guanzhu
    from 
        user_base a 
        left join new_weituo_person b on a.uid=b.uid
        inner join new_weituo_fensi c on a.uid=c.uid
        left join (select uid,count(id) as ct from new_weituo_fensi ";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." where hd_id='".$hd_id."' ";
}
$sql .="		group by uid) d on d.uid=c.uid
        left join (select fuid,count(id) as ct from new_weituo_fensi ";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." where hd_id='".$hd_id."' ";
}
$sql .=" group by fuid) e on e.fuid=c.uid
        left join (select uid,count(id) as ct from new_weituo_zuopin where dr='0' and aflag='1' ";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and hd_id='".$hd_id."' ";
}
$sql .="		group by uid) f on f.uid=c.uid
		left join (select fuid,id from new_weituo_fensi where uid='".$uid."' ";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and hd_id='".$hd_id."' ";
}
$sql .= ") g on g.fuid=c.uid
        where c.fuid='".$uid."'";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and c.hd_id='".$hd_id."' ";
}
$sql = $sql." limit ".($page * $pagesize).",".$pagesize;
$db->query($sql);
$gzuersArr = array();	
while($db->next_record()){
	
	$nickName = $db->f("nickname");
	if($nickName==null){
		$nickName = user_fix_mobile($db->f("mobile"));
	}
	$userCollege = $db->f("userCollege");
	if($userCollege==null){
		$userCollege = "";
	}
	$userIcon = $db->f("userIcon");
	$hasILogo = "0"; //是否存在头像
	if($userIcon==null){
		//默认头像
		$userIcon = $LOGO_DEFAULT_PATH;
	}else{
		$userIcon = $LOGO_BASE_PATH.$userIcon;
		$hasILogo = "1";
	}
	//是否被粉丝关注
	$guanzhu = $db->f("guanzhu");
	if($guanzhu==null){
		$guanzhu = "0";	//我关注了粉丝
	}else{
		$guanzhu = "1";	//相互关注
	}
	$gzuersArr[] = array(
		 "userName"			=>	$nickName				//作者名称
		,"userIcon"			=>	$userIcon				//作者头像地址
		,"userCollege"		=>	$userCollege			//作者学校
		,"attention"		=>	(string)$db->f("attention")==null?"0":$db->f("attention")	//关注总数
		,"fans"				=>	(string)$db->f("fans")==null?"0":$db->f("fans")				//粉丝总数
		,"works"			=>	(string)$db->f("works")==null?"0":$db->f("works")			//作品总数
		,"userId"			=>	$db->f("uid")			//uid
		,"guanzhu"			=>	$guanzhu				//是否被粉丝关注  0我关注了粉丝  1相互关注
		,"has_ilogo"		=>	$hasILogo				//用户是否设置了头像 0没设置  1设置
	);
}	
$reJson["list"]=$gzuersArr;
echo json_encode($reJson);
?>